/*
Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.

If the last word does not exist, return 0.

Note: A word is defined as a character sequence consists of non-space characters only.

For example,
Given s = "Hello World",
return 5.

*/

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <stack>
#include <fstream>
#include <sstream>
#include "print.h"
using namespace std;


void testForStack()
{
	stack<int> mystack;
	mystack.push(10);
	mystack.push(20);
	mystack.top() -= 5;
	cout << "mystack.top() is now " << mystack.top() << endl;
}

void testForIntToString()
{
	int a = 10;
	stringstream ss;
	ss << a;
	string str = ss.str();
	cout << str << endl;

	string str1 = to_string(a);

}


class Solution {
public:
	int lengthOfLastWord(const char *s) {
		int len = strlen(s);
		bool flag = true;
		int count = 0;
		if (len == 0)
		{
			return 0;
		}
		for (int i = len - 1; i >= 0; i--)
		{
			if ( flag && s[i] == ' ')
			{
				continue;

			}else if (s[i] != ' ')
			{
				count++;
				flag = false;
			}
			else{
				return count;
			}
		}
		
		return count;
	}
};
int main(int argc, char* argv[])
{

	testForIntToString();
	Solution s;
	char *word = "";
	for (int i = 1; i < argc; i++){

		cout << argv[i] << endl;
		//arrInt[i - 1] = atoi(argv[i]);
		//str = argv[i];
		//charPtr = argv[i];
		//fileName = argv[i];
		word = argv[i];

	}

	word = "a ";
	cout << strlen(word)<< endl;
	cout << word[0]<< endl; 
	cout << "lengthOfLastWord: " << s.lengthOfLastWord(word) << endl;



	system("pause");
	return 0;
}